package main

import (
	"fmt"
	"io/ioutil"

	"gopkg.in/yaml.v2"
)

type Configure struct {
	ServerIP  string `yaml:"server_ip"`
	GrpcPort  string `yaml:"server_port"`
	AdminPort string `yaml:"admin_port"`
	WorkerNum int    `yaml:"worker_num"`
}

func LoadConfig(fileName string) (*Configure, error) {
	config := Configure{}
	content, err := ioutil.ReadFile(fileName)
	if err != nil {
		return &config, fmt.Errorf("LoadConfig.ReadFile: %v", err)
	}
	err = yaml.Unmarshal(content, &config)
	if err != nil {
		return &config, fmt.Errorf("LoadConfig.Parse: %v", err)
	}
	return &config, nil
}
